#!/usr/bin/env python 
from PyQt4.uic.Compiler.compiler import UICompiler
import os

class Compiler(UICompiler):
    def __init__(self, file):
        UICompiler.__init__(self)
        self.filename=file


    #def compileUi(self, input_stream, output_stream, from_imports):
    #    self.filename=input_stream
    #    super ( Compiler, self ).compileUi(input_stream, output_stream, from_imports)

    def readResources(self, elem):
        """
        Read a "resources" tag and add the module to import to the parser's
        list of them.
        """
	loc = ''
        for include in elem.getiterator("include"):
            loc = include.attrib.get("location")

        # Assume our convention for naming the Python files generated by
        # pyrcc4

        file_dirs = os.path.splitdrive (os.path.dirname(self.filename) ) [1].split(os.sep)
        base_dirs = os.path.splitdrive(os.getcwd()) [1].split(os.sep)
        imp_path ='.'.join ([ x for x in file_dirs if x not in base_dirs ])

        if loc and loc.endswith('.qrc'):
            self.resources.append( imp_path + '.' + os.path.basename(loc[:-4] + '_rc'))
